package cn.toma.core.web.jsonconfig;

import com.fasterxml.jackson.databind.ObjectMapper;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;

import java.text.SimpleDateFormat;

/**
 * @author zqx
 * @version 1.0.0
 * @ClassName JsonConfig.java
 * @Description
 * @createTime 2019年08月28日 21:29:00
 */
@Configuration
public class JacksonConfig
{
	@Bean
	public MappingJackson2HttpMessageConverter mappingJacksonHttpMessageConverter()
	{
		final MappingJackson2HttpMessageConverter converter = new MappingJackson2HttpMessageConverter();

		ObjectMapper mapper = converter.getObjectMapper();
		SimpleDateFormat smt = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		mapper.setDateFormat(smt);
		//解决时区差8小时问题
//		mapper.setTimeZone(TimeZone.getTimeZone("GMT+8"));
		// 为mapper注册一个带有SerializerModifier的Factory，此modifier主要做的事情为：当序列化类型为array，list、set时，当值为空时，序列化成[]
		mapper.setSerializerFactory(mapper.getSerializerFactory().withSerializerModifier(new MyBeanSerializerModifier()));
		return converter;
	}


}
